package com.liuyang.homework.Fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.liuyang.homework.Adapter.NewsAdapter;
import com.liuyang.homework.Bean.News;
import com.liuyang.homework.Bean.NewsLab;
import com.liuyang.homework.R;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DataFragment extends Fragment {

    RecyclerView rvData;
    List<News> news;
    NewsAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_data, container, false);
        rvData= (RecyclerView) view.findViewById(R.id.rv_data);
        rvData.setLayoutManager(new LinearLayoutManager(getContext()));
        rvData.setItemAnimator(new DefaultItemAnimator());

        initData();
        return view;
    }

    private void initData() {
        news = new NewsLab(getContext()).getNews();
        if (news.size()>0){
            adapter= new NewsAdapter(news,getContext());
            rvData.setAdapter(adapter);
        }
    }

}
